package com.easy.sk.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SeckillProduct;
import com.easy.common.service.ISeckillProductService;
import com.easy.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 秒杀商品表 前端控制器
 * </p>
 *
 * @author Easy
 * @since 2025-09-09
 */
@RestController
@RequestMapping("/skproduct")
@CrossOrigin
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;


    @GetMapping("{id}")
    public Result getOne(@PathVariable("id") Integer id){
        return Result.success(seckillProductService.getById(id));
    }
    @GetMapping("page")
    public Result page(SeckillProduct seckillProduct, Page page){
        return Result.success(seckillProductService.page(page,new QueryWrapper<>(seckillProduct)));
    }
    @PostMapping
    public Result save(@RequestBody SeckillProduct seckillProduct){
        return Result.success(seckillProductService.save(seckillProduct));
    }
    @PutMapping
    public Result update(@RequestBody SeckillProduct seckillProduct){
        return Result.success(seckillProductService.updateById(seckillProduct));
    }
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success(seckillProductService.removeById(id));
    }
}
